#include "thread.h"


namespace tinySrv
{
  Thread::Thread(ICallbackPtr callback)
  {
    int Result = pthread_create(&Handle, 0, &Thread::ThreadProc, callback.get());
    if (Result)
      throw ThreadException("Can't create thread", Result);
    Callback = callback;
  }
  
  Thread::~Thread()
  {
    pthread_join(Handle, 0);
  }

  void* Thread::ThreadProc(void *prm)
  {
    reinterpret_cast<ICallback *>(prm)->Do();
    return 0;
  }
  
}
